/*
 * MIT License
 * 
 * Copyright (c) 2017 wen.gu <454727014@qq.com>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*****************************************************************************
 * Name:general_type.h
 *
 * Purpose: standard header,and unified data type define
 *
 * Note: 'G' in macro and data type indicate 'general'
 *     
 * Version: 0.3
 *
 * Developer:
 * wen.gu, 2016-04-06
 *
 *****************************************************************************/

#ifndef __GENERAL_TYPE_H__
#define __GENERAL_TYPE_H__
#include <stdio.h>
#include <stdlib.h>

/**
 * general type define and some keyword Compatible.
 * The user can define the following macros in the build script to
 * control library's behavior.  If the user doesn't define a macro
 * in this list, general_type.h will define it.
 * DLL_EXPORT          - Define to 1 when compiling library itself
 *                           as a shared library.
 * 
 */

/***************************************************************************
 * general data type define.
 ***************************************************************************/
typedef void*              GPHD;  //general instance handle type
typedef void*              GADR;  //general address type
typedef void*              GPTR;  //general pointer type
typedef char*              GSTR;  //general string type
typedef char               GCHR;  //general character type
typedef wchar_t            GWCH;  //general width character type.

//general signed integer type
typedef char               GS08;  //8  bits
typedef short              GS16;  //16 bits
typedef int                GS32;  //32 bits
typedef long long          GS64;  //64 bits

//general unsigned integer type
typedef unsigned char      GU08; //8 bits
typedef unsigned short     GU16; //16 bits
typedef unsigned int       GU32; //32 bits
typedef unsigned long long GU64; //64 bits

//general float type
typedef float              GFLT;
typedef double             GDBL;

//boolean type declaration
typedef GU32 GBOL;

#ifndef GTRUE /** boolean true */
#define GTRUE 1
#endif

#ifndef GFALSE /** boolean false */
#define GFALSE 0
#endif

/***************************************************************************
 * general data type limit(maximum and minmum) value define.
 ***************************************************************************/
#define GS08_MIN   (-127 - 1)
#define GS16_MIN   (-32767 - 1)
#define GS32_MIN   (-2147483647 - 1)
#define GS64_MIN   (-9223372036854775807LL - 1)
#define GS08_MAX   127
#define GS16_MAX   32767
#define GS32_MAX   2147483647
#define GS64_MAX   9223372036854775807LL
#define GU08_MAX   0xff
#define GU16_MAX   0xffff
#define GU32_MAX   0xffffffff
#define GU64_MAX   0xffffffffffffffffULL

/***************************************************************************
 * define extern "C" macro.
 ***************************************************************************/
#ifdef __cplusplus
#define G_EXTERN_C extern "C"
#else
#define G_EXTERN_C 
#endif

/***************************************************************************
 * macro define for specfial toolchain.
 ***************************************************************************/
#if defined(__GNUC__) /** !!!for gcc */
////////////////////////////////////////////////////////////////////////////
#define G_GCC_VERSION(maj,min) \
    ((__GNUC__ > (maj)) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))

/** define API export  macro */
#if G_GCC_VERSION(4,0) //for gcc(version >= 4.0)
#define G_DLL_EXPORT __attribute__((visibility("default")))
#else
#define G_DLL_EXPORT
#endif

#elif defined(_MSC_VER) /** !!!for visual studio */
////////////////////////////////////////////////////////////////////////////
/** compat the keyword 'inline' */
#if (_MSC_VER > 1200) && !defined (__cplusplus)
#define inline    _inline  /** to compat keyword 'inline' */
#endif

/** auto define API export macro */
#if !defined(DLL_EXPORT) && defined(_WINDLL) //todo,process _USRDLL,_AFXDLL
#define DLL_EXPORT
#endif

#if defined (DLL_EXPORT)
#define G_DLL_EXPORT __declspec(dllexport)
#else
#define G_DLL_EXPORT

#endif

#else /** !!!for unknown toolchain */
///////////////////////////////////////////////////////////////////////////
#error "!!unspport this toolchain at now!!"
#endif /** !!! end of toolchin define */

/***************************************************************************
 * default macro define.
 ***************************************************************************/
/** the flag of file operation */
#if !defined(G_FS_BITS)
/** 
 * default enable large file operation, here just indicate os API,
 * whether support large file, Decision by file system.
 */
#define G_FS_BITS 64  
#endif


/***************************************************************************
 * common macro define.
 ***************************************************************************/

/** general api decorate macro */
#define G_API G_EXTERN_C G_DLL_EXPORT

/** general class decorate macro*/
#define G_CLASS G_DLL_EXPORT

/** general global variable decorate macro(for external reference ) */
#define G_VAR  extern G_DLL_EXPORT 

/** general const global variable decorate macro(for external reference ) */
#define G_CVAR G_VAR const

/** path separator define */
#if defined(_MSC_VER)
#define PATH_SEPARATOR '\\'
#else
#define PATH_SEPARATOR '/'
#endif
/***************************************************************************
 * some special data type define.
 ***************************************************************************/

#endif //end of __GENERAL_TYPE_H__
 
